package com.yeban.javase.day02.test06;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/10
 */
public class Order {

    private long orderNum;
    private User user;
    private Goods[] goodsList;
    private int goodsCount;

    public Order() {
    }

    public Order(long orderNum, User user, int maxGoods) {
        this.orderNum = orderNum;
        this.user = user;
        this.goodsList = new Goods[maxGoods];
        this.goodsCount = 0;    // 初始化商品数量为0
    }

    // 添加商品到订单
    public void addGoods(Goods good) {
        if (goodsCount < goodsList.length) {
            goodsList[goodsCount] = good;
            goodsCount++;
        } else {
            System.out.println("订单商品已满！");
        }
    }

    /**
     * 查看商品详情信息
     */
    public void viewInformation() {
        double totalAmount = 0;
        for (int i = 0; i < goodsCount; i++) {
            System.out.println("\n----------第个" +  (i + 1) + "商品 " + "----------");
            goodsList[i].displayInfo();
            totalAmount += goodsList[i].getPrice() * goodsList[i].getNum();
        }

        System.out.println("\n==============================");
        System.out.println("订单总金额：¥" + totalAmount);
        System.out.println("==============================\n");
    }

    /**
     * 获取
     * @return num
     */
    public long getNum() {
        return orderNum;
    }

    /**
     * 设置
     * @param orderNum
     */
    public void setNum(long orderNum) {
        this.orderNum = orderNum;
    }

    /**
     * 获取
     * @return user
     */
    public User getUser() {
        return user;
    }

    /**
     * 设置
     * @param user
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * 获取
     * @return goods
     */
    public Goods[] getGoods() {
        return goodsList;
    }

    /**
     * 设置
     * @param goods
     */
    public void setGoods(Goods[] goods) {
        this.goodsList = goods;
    }

    public String toString() {
        return "Order{num = " + orderNum + ", user = " + user + ", goods = " + goodsList + "}";
    }
}
